package com.hec.yygh.hosp.controller.api;

import com.hec.yygh.common.result.R;
import com.hec.yygh.hosp.service.DepartmentService;
import com.hec.yygh.hosp.service.HospitalService;
import com.hec.yygh.hosp.service.ScheduleService;
import com.hec.yygh.model.hosp.Hospital;
import com.hec.yygh.model.hosp.Schedule;
import com.hec.yygh.vo.hosp.HospitalQueryVo;
import com.hec.yygh.vo.hosp.ScheduleOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;


    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    /**获取排班详情
     */
    @GetMapping("getSchedule/{id}")
    public R getScheduleList(
            @PathVariable("id") String id) {
        Schedule schedule = scheduleService.getScheduleById(id);
        return R.ok().data("schedule",schedule);
    }

    /**
     * 获取可预约排班数据
     */
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {
        Map<String,Object> map = scheduleService.getBookingSchedule(page,limit,hoscode,depcode);
        return R.ok().data(map);
    }

    /**
     * 获取排班数据
     */
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }

    /**
     * 根据医院编号查询医院信息
     * @param hoscode
     * @return
     */
    @GetMapping("/{hoscode}")
    public R getHospitalInfoByHoscede(@PathVariable("hoscode")String hoscode){
        Hospital byHoscode = hospitalService.getByHoscode(hoscode);
        return R.ok().data("hospital",byHoscode);
    }

    /**
     * 根据医院编号查询科室信息,大科室嵌套小科室
     * @param hoscode
     * @return
     */
    @GetMapping("/department/{hoscode}")
    public R getDepartmentListByHoscede(@PathVariable("hoscode")String hoscode){
        return departmentService.getAllDepartments(hoscode);
    }

    @GetMapping("/{page}/{limit}")
    public R getHospitalPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             HospitalQueryVo hospitalQueryVo){

        Page<Hospital> pageModel = hospitalService.selectPage(page,limit,hospitalQueryVo);
        log.info("pageModel"+pageModel);
        return R.ok().data("pages",pageModel);
    }

    @GetMapping("/findByHosname/{name}")
    public R findByNameLike(@PathVariable("name")String name){
        List<Hospital> hospitalList = hospitalService.findByNameLike(name);
        return R.ok().data("list",hospitalList);
    }
}
